package com.company.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.project.entity.StudentEntity;
import com.company.project.mapper.StudentMapper;
import com.company.project.service.StudentService;
import com.company.project.vo.resp.StudentVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;


@Service("studentService")
public class StudentServiceImpl extends ServiceImpl<StudentMapper, StudentEntity> implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public IPage<StudentVo> pageInfo(StudentVo studentVo) {
        QueryWrapper<StudentEntity> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(studentVo.getName())){
            queryWrapper.like("s.name", studentVo.getName());
        }
        if (!ObjectUtils.isEmpty(studentVo.getClassId())){
            queryWrapper.eq("s.class_id", studentVo.getClassId());
        }
        Page page = studentVo.getQueryPage();
        List<StudentVo> studentVos = studentMapper.listPage(studentVo.getQueryPage(), queryWrapper);
        page.setRecords(studentVos);
//        IPage iPage = studentMapper.selectPage(studentVo.getQueryPage(), queryWrapper);
        return page;
    }
}